import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */

/*
  hidden:true的菜单不会显示
  meta:{title菜单标题，icon菜单图片}
  alwaysShow:truw,一直显示菜单上(不管什么情况都会显示菜单上)
  默认规则：如果一个子集菜单显示，默认是没有二级菜单的，超过一个就会显示二级菜单
*/

/*
  将路由分成第二部分：
      静态路由：不需要权限管理由 404 首页 login
      动态路由：需要权限管理路由

      1.区分路由为静态(404,首页，login)
      2.动态路由匹配与添加
            怎么匹配？
                在动态路由中加入meta:{name:权限标识}与权限数据匹配
            什么时间匹配？
                在匹配到用户信息后匹配：vuex中
            怎么添加
                router提供的方法
                   router.addRouter([需要添加的路由])
                   'router'路由实例对象

*/
export const otherRouters = [
  {
    path: '/Gonshi',
    component: Layout,
    meta: {
      name: 'settings'
    },

    children: [

      {
        path: '',
        component: () => import('@/views/Gonshi'),
        //      名字               图标
        meta: { title: '公司', icon: 'dashboard' }
      }

    ]
  },
  {
    path: '/shenpi',
    component: Layout,
    meta: {
      name: 'approvals'
    },

    children: [

      {
        path: '',
        component: () => import('@/views/Shenpi'),
        //      名字               图标
        meta: { title: '审批', icon: 'dashboard' }
      }

    ]
  },

  {
    path: '/Gonzi',
    component: Layout,
    meta: {
      name: 'salarys'
    },
    children: [

      {
        path: '',
        component: () => import('@/views/Gonzi'),
        //      名字               图标
        meta: { title: '工资', icon: 'dashboard' }
      }

    ]
  },

  {
    path: '/Kaoqin',
    component: Layout,
    meta: {
      name: 'attendances'
    },
    children: [

      {
        path: '',
        component: () => import('@/views/Kaoqin'),
        //      名字               图标
        meta: { title: '考勤', icon: 'dashboard' }
      }

    ]
  },

  {
    path: '/QuanXuan',
    component: Layout,
    meta: {
      name: 'permissions'
    },
    children: [

      {
        path: '',
        component: () => import('@/views/QuanXuan'),
        //      名字               图标
        meta: { title: '权限', icon: 'dashboard' }
      }

    ]
  },

  {
    path: '/SeBao',
    component: Layout,
    meta: {
      name: 'social_securitys'
    },
    children: [

      {
        path: '',
        component: () => import('@/views/SeBao'),
        //      名字               图标
        meta: { title: '社保', icon: 'dashboard' }
      }

    ]
  },

  {
    path: '/Yangon',
    meta: {
      name: 'employees'
    },
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/Yuangon'),
        //      名字               图标
        meta: { title: '员工', icon: 'dashboard' }
      },
      {
        path: 'excle',
        component: () => import('@/views/Yuangon/excel.vue'),
        hidden: true
      },
      {
        path: 'xianqin/:id?',
        component: () => import('@/views/Yuangon/xianqin.vue'),
        hidden: true
      }
    ]
  },

  {
    path: '/Zuzhijiagou',
    component: Layout,
    meta: {
      name: 'departments'
    },
    children: [

      {
        path: '',
        component: () => import('@/views/Zuzhijiagou'),
        //      名字               图标
        meta: { title: '组织结构', icon: 'dashboard' }
      }

    ]
  }
]
export const constantRoutes = [
  // 先展开，做调试处理
  // ...otherRouters,
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true // 是否显示菜单
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }

      }

    ]
  }

  // 404 page must be placed at the end !!!

]

// 重置路由 resetRouter()

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
